home *** CD-ROM | disk | FTP | other *** search
- #ifndef __PARSERACTIONS__
- #define __PARSERACTIONS__ 1
-
- #ifndef __CSCANNER__
- #include "CScanner.h"
- #endif
-
- #ifndef __PARSER__
- #include "Parser.h"
- #endif
-
-
- #pragma segment ParserActions
-
-
- /*
- ** Define the types that parse items can be.
- */
- enum {
- kSLex_Flush = kSLex_Last + 1 // Unblocks Prs_Id/Prs_DeclOperator
- , kSLex_Context // Formatting context marker
-
- , kSPrs_Id = kSPrs // Base parse type
- , kSPrs_StmtList //
- , kSPrs_DeclList //
- , kSPrs_DeclType //
- , kSPrs_Stmt //
- , kSPrs_Decl //
- , kSPrs_Do //
- , kSPrs_If //
- , kSPrs_Else //
- , kSPrs_For //
- , kSPrs_Struct //
- , kSPrs_Switch //
- , kSPrs_While //
- , kSPrs_Expr //
- , kSPrs_DeclOperator //
- , kSPrs_NewLine //
- };
-
-
- /*µ class SyntacticPrs
- ** This class is the abstract base class for grammar derived items. As
- ** such, none of the items are separators. The default behavior for SaveCopy
- ** is to return itself; this will be overridden in derived classes which
- ** contain state information. The Display method will definitely be overridden.
- */
-
- class SyntacticPrs : public Syntactic {
- public:
- SyntacticPrs(int aType);
-
- virtual Boolean IsSeparator() const;
- /*
- ** Returns false.
- */
-
- virtual const Syntactic *SaveCopy() const;
- /*
- ** Returns itself.
- */
-
- virtual Boolean Display(Formatting *aFormat);
- /*
- ** Display is not done by the object. Display is done by the
- ** accept method.
- */
-
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser) = 0;
- /*
- ** The major parse method. Items on the stack are handed tokens
- ** and the current parser. If the token can be used, the method
- ** (possibly) modifies aParser and returns true. If the token
- ** cannot be used, the method returns false. The parser then
- ** tries the next Syntactic* on the parse stack until the stack
- ** is empty, at which point the token is pushed onto the stack
- ** until such time as it can be used.
- */
- };
-
-
- //µ SyntacticPrs::SyntacticPrs
- #pragma segment ParserActions
- inline SyntacticPrs::SyntacticPrs(int aType)
- : Syntactic(aType)
- {
- }
-
-
-
- /*µ class PrsPlaceHolder
- ** This class does nothing except contain a type. Instances of this type are
- ** used as place holders on the parse stack.
- */
-
- class PrsPlaceHolder : public SyntacticPrs {
- public:
- PrsPlaceHolder(int aType);
- PrsPlaceHolder(int aType, const char *aString);
-
- virtual Boolean Display(Formatting *aFormat);
- virtual Boolean Accept(Syntactic *, Parser *);
-
- private:
- const char *fString; // Optional string to display
- };
-
-
- //µ PrsPlaceHolder::PrsPlaceHolder
- #pragma segment ParserActions
- inline PrsPlaceHolder::PrsPlaceHolder(int aType)
- : SyntacticPrs(aType),
- fString(0)
- {
- }
-
-
- inline PrsPlaceHolder::PrsPlaceHolder(int aType, const char *aString)
- : SyntacticPrs(aType),
- fString(aString)
- {
- }
-
-
-
- /*µ class PrsId
- ** This class encapsulates the concept of a qualified name, one with a
- ** "::" or "::*" in it. It is through this class that kSLex_Id are
- ** transformed into kSLex_ParsedId.
- */
- class PrsId : public SyntacticPrs {
- public:
- PrsId();
- PrsId(Syntactic *aClassName, Syntactic *aMemberName, Syntactic *aClassOp);
-
- virtual Boolean Display(Formatting *aFormat);
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
-
- private:
- Syntactic *fClassName;
- Syntactic *fMemberName;
- Syntactic *fClassOp;
- };
-
-
- //µ PrsId::PrsId
- #pragma segment ParserActions
- inline PrsId::PrsId()
- : SyntacticPrs(kSPrs_Id),
- fClassName(0),
- fMemberName(0),
- fClassOp(0)
- {
- }
-
-
- inline PrsId::PrsId(Syntactic *aClassName, Syntactic *aMemberName, Syntactic *aClassOp)
- : SyntacticPrs(kSLex_ParsedId),
- fClassName(aClassName),
- fMemberName(aMemberName),
- fClassOp(aClassOp)
- {
- }
-
-
-
- /*µ class PrsAsId
- ** This class cloaks kSLex_Public keywords as respectable kSLex_ParsedId
- ** keywords. Used to support C code which has variables called "public",
- ** "private" and "protected".
- */
- class PrsAsId : public PrsPlaceHolder {
- public:
- PrsAsId(Syntactic *aName);
-
- virtual Boolean Display(Formatting *aFormat);
-
- private:
- Syntactic *fToken; // The token of interest.
- };
-
-
- //µ PrsAsId::PrsAsId
- #pragma segment PrsAsId
- inline PrsAsId::PrsAsId(Syntactic *aName)
- : PrsPlaceHolder(kSLex_ParsedId),
- fToken(aName)
- {
- }
-
-
-
- /*µ class PrsDestructor
- ** This class displays destructor names. That's all. Thank you.
- */
- class PrsDestructor : public PrsPlaceHolder {
- public:
- PrsDestructor(Syntactic *aMemberName);
-
- virtual Boolean Display(Formatting *aFormat);
-
- private:
- Syntactic *fMemberName;
- };
-
-
- //µ PrsDestructor::PrsDestructor
- #pragma segment ParserActions
- inline PrsDestructor::PrsDestructor(Syntactic *aMemberName)
- : PrsPlaceHolder(kSLex_ParsedId),
- fMemberName(aMemberName)
- {
- }
-
-
-
- //µ class PrsStmtList
- class PrsStmtList : public SyntacticPrs {
- public:
- PrsStmtList()
- : SyntacticPrs(kSPrs_StmtList)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsDeclList
- class PrsDeclList : public SyntacticPrs {
- public:
- PrsDeclList()
- : SyntacticPrs(kSPrs_DeclList)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsStmt
- class PrsStmt : public SyntacticPrs {
- public:
- PrsStmt()
- : SyntacticPrs(kSPrs_Stmt)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsDecl
- class PrsDecl : public SyntacticPrs {
- public:
- PrsDecl()
- : SyntacticPrs(kSPrs_Decl)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsDo
- class PrsDo : public SyntacticPrs {
- public:
- PrsDo()
- : SyntacticPrs(kSPrs_Do)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsIf
- class PrsIf : public SyntacticPrs {
- public:
- PrsIf()
- : SyntacticPrs(kSPrs_If)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsElse
- class PrsElse : public SyntacticPrs {
- public:
- PrsElse()
- : SyntacticPrs(kSPrs_Else)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsFor
- class PrsFor : public SyntacticPrs {
- public:
- PrsFor()
- : SyntacticPrs(kSPrs_For)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsStruct
- class PrsStruct : public SyntacticPrs {
- public:
- PrsStruct()
- : SyntacticPrs(kSPrs_Struct)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsSwitch
- class PrsSwitch : public SyntacticPrs {
- public:
- PrsSwitch()
- : SyntacticPrs(kSPrs_Switch)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsWhile
- class PrsWhile : public SyntacticPrs {
- public:
- PrsWhile()
- : SyntacticPrs(kSPrs_While)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsExpr
- class PrsExpr : public SyntacticPrs {
- public:
- PrsExpr()
- : SyntacticPrs(kSPrs_Expr)
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- //µ class PrsDeclOperator
- class PrsDeclOperator : public SyntacticPrs {
- public:
- PrsDeclOperator(int aType = kSPrs_DeclOperator)
- : SyntacticPrs(aType)
- {
- }
-
- virtual Boolean Display(Formatting *aFormat);
- virtual Boolean Accept(Syntactic *, Parser *);
-
- private:
- Syntactic *fToken; // The token of interest.
- };
-
-
-
- /*µ class PrsNewLine
- ** This class implements "deferred newlines". When source newlines are not
- ** being passed directly through to the output (aFormat->PassSourceNewLines()
- ** is false), a newline can be ambiguous. For example, if we are to
- ** format "if(){}else" as
- **
- ** if () {
- ** } else
- **
- ** and format "if(){}foo++;" as
- **
- ** if () {
- ** }
- ** foo++;
- **
- ** and the input is "if(){} <newline>", we don't know what to do. Because we
- ** emit are two or more consecutive newlines, we are not at liberty to ignore
- ** this newline. We could extend the grammar and save the newline, but this
- ** becomes very complicated as in the particular case above the close curly
- ** has not been emitted yet, as it is awaiting the "else" or <other> to
- ** determine which glue to use for displaying it.
- **
- ** Consequently, grammar actions sensitive to these points push an instance
- ** of this class onto the stack when the input token is of type kSLex_NewLine.
- ** If the newline should have been ignored, it will be ignored. If the newline
- ** should not be ignored, it will come back as being of type kSPrs_NewLine.
- */
- class PrsNewLine : public SyntacticPrs {
- public:
- PrsNewLine()
- : SyntacticPrs(kSPrs_NewLine)
- {
- }
-
- virtual Boolean IsSeparator() const;
- virtual Boolean Display(Formatting *aFormat);
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
- /*µ class PrsNewLineIf
- ** Like PrsNewLine, except it also ignores the newline if it is followed by
- ** "if". Used in the context of "else <newline> if" to treat it as "else if"
- */
- class PrsNewLineIf : public PrsNewLine {
- public:
- PrsNewLineIf()
- : PrsNewLine()
- {
- }
-
- virtual Boolean Accept(Syntactic *aToken, Parser *aParser);
- };
-
-
-
- /*
- ** Externed items
- */
- extern PrsDeclList gPrsDeclList;
- extern PrsId gPrsId;
- extern PrsPlaceHolder gLexFlush;
-
- #endif
-
-
-